package com.mohan.gulimall.product.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.mohan.gulimall.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.mohan.gulimall.product.entity.AttrGroupEntity;
import com.mohan.gulimall.product.service.AttrGroupService;
import com.mohan.common.utils.PageUtils;
import com.mohan.common.utils.R;


/**
 * 属性分组
 *
 * @author mohan
 * @email 1358665425@qq.com
 * @date 2021-12-11 09:47:42
 */
@RestController
@RequestMapping("product/attrgroup")
public class AttrGroupController {
  @Autowired
  private AttrGroupService attrGroupService;

  @Autowired
  private CategoryService categoryService;

  /**
   * 列表
   */
  @RequestMapping("/list/{catelogId}")
  //@RequiresPermissions("product:attrgroup:list")
  public R list(@RequestParam Map<String, Object> params,@PathVariable Long catelogId) {
    PageUtils page = attrGroupService.queryPage(params,catelogId);

    return R.ok().put("page", page);
  }


  /**
   * 信息
   */
  @RequestMapping("/info/{attrGroupId}")
  //@RequiresPermissions("product:attrgroup:info")
  public R info(@PathVariable("attrGroupId") Long attrGroupId) {
    AttrGroupEntity attrGroup = attrGroupService.getById(attrGroupId);

    Long catelogId = attrGroup.getCatelogId();
    Long[] path = categoryService.findCateLogPath(catelogId);
    attrGroup.setCatelogPath(path);
    return R.ok().put("attrGroup", attrGroup);
  }

  /**
   * 保存
   */
  @RequestMapping("/save")
  //@RequiresPermissions("product:attrgroup:save")
  public R save(@RequestBody AttrGroupEntity attrGroup) {
    attrGroupService.save(attrGroup);

    return R.ok();
  }

  /**
   * 修改
   */
  @RequestMapping("/update")
  //@RequiresPermissions("product:attrgroup:update")
  public R update(@RequestBody AttrGroupEntity attrGroup) {
    attrGroupService.updateById(attrGroup);

    return R.ok();
  }

  /**
   * 删除
   */
  @RequestMapping("/delete")
  //@RequiresPermissions("product:attrgroup:delete")
  public R delete(@RequestBody Long[] attrGroupIds) {
    attrGroupService.removeByIds(Arrays.asList(attrGroupIds));

    return R.ok();
  }

}
